from ..testLogin.LoginOperation import LoginOperation
from ..PublicOperations import PublicOperations
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class OnlineOperate:

    def online_operate(self, driver, username, pwd, money, moneyTime):
        log = LoginOperation()
        log.login(driver, username, pwd)
        PublicOperations.Operate(driver, 3, 2)

        driver.find_element(By.XPATH, "//input[@id='amount']").send_keys(money)
        driver.find_element(By.XPATH, "//input[@id='term']").send_keys(moneyTime)
        driver.find_element(By.XPATH, "//button[@id='submit']").click()
        time.sleep(1)
        driver.find_element(By.XPATH, "//div[@class='jconfirm-buttons']/button[1]").click()
        time.sleep(0.5)
        # 点击申请按钮

    def online_operate2(self,driver, username, pwd, money, moneyTime):
        log = LoginOperation()
        log.login(driver, username, pwd)
        PublicOperations.Operate(driver, 3, 2)

        driver.find_element(By.XPATH, "//input[@id='amount']").send_keys(money)
        driver.find_element(By.XPATH, "//input[@id='term']").send_keys(moneyTime)
        driver.find_element(By.XPATH, "//button[@id='submit']").click()
        time.sleep(1)


    def get_tishi_result(self, driver):
        ele = WebDriverWait(driver, 10, 0.1).until(
            EC.presence_of_element_located((By.XPATH, "//div[@class='jconfirm-content']/div")))

        return ele.text

    def get_tishi_result2(self,driver):
        time.sleep(1)
        return driver.find_element(By.XPATH,"//div[@class='jconfirm-content']/div").text

    def get_tishi_result3(self,driver):
        time.sleep(1)
        ans = ''
        try:
            ans = driver.find_element(By.XPATH,"/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[1]/span").text
        except:
            pass

        return ans

    def get_tishi_result4(self,driver):
        time.sleep(1)
        ans = ''
        try:
            ans = driver.find_element(By.XPATH,"/html/body/div[1]/div/main/div/div/div/div/div[2]/div/form/div[3]/span").text
        except:
            pass

        return ans



    def admin_online_operate(self, driver, username, pwd):
        log = LoginOperation()
        log.login(driver=driver, name=username, pwd=pwd)
        #  管理员 进行登录操作
        PublicOperations.Operate(driver, 5, 1)
        # 点击网贷审核
        driver.find_element(By.XPATH, "//nav[contains(@aria-label,'Page')]/ul/li[last()]/a").click()
        # 点击末页按钮
        time.sleep(1)
        driver.find_element(By.XPATH,
                            "//div[@class='card-body']/div/table/tbody/tr[last()]/td[last()]/button[1]").click()
        # 点击 审核通过 按钮
        time.sleep(2)
        driver.find_element(By.XPATH, "//div[@class='jconfirm-buttons']/button[1]").click()
        # 点击确认按钮
        driver.quit()
